import axios from "axios";
const url = import.meta.env.VITE_backurl;
const urlTrue = import.meta.env.VITE_backurl_JAVA;
const urlTom = import.meta.env.VITE_backurl_warndoc;
const urlDl = import.meta.env.VITE_backurl_dalian;

// 获取综合预报数据
export const getForecast = (satoken, params) => {
  // let u = 'http://101.231.140.173:8088/QinShanDataInterface/handler/OceanRefinementHandler.ashx?m=getComprehensiveForecast '
  return axios({
    method: "get",
    // url: urlTrue + "/comprehensive/getAllComprehensive",
    url: urlTrue + "/comprehensive/searchComprehensiveByDepartment",
    headers: {
      Authorization: "Bearer", //表示后端的接口需要token
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
      satoken: satoken,
    },
    params: {
      time: new Date().getTime(),
      ...params,
    },
  });
};

// 潮位预报
// http://101.231.140.173:8088/QinShanDataInterface/handler/OceanRefinementHandler.ashx?m=getSingPointNCData&elementType=3&lon=120.9516494083&lat=30.443767681300002
export const getTide = (lon, lat) => {
  let u =
    "http://101.231.140.173:8088/QinShanDataInterface/handler/OceanRefinementHandler.ashx?m=getSingPointNCData&elementType=3&lon=120.9516494083&lat=30.443767681300002";
  return axios({
    method: "get",
    url: u,
    params: {
      time: new Date().getTime(),
    },
  });
};

// 登录
export const login = (data) => {
  return axios({
    method: "post",
    url: urlTrue + "/user/login",
    data: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
      Authorization: "Bearer",
    },
  });
};

// 24小时逐个小时潮位查询
export const getTide24 = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/tide/searchTideOfHours",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
      // pntId: 14,
      time: new Date().getTime(),
    },
  });
};

// 查询当月的月高低潮数据
export const getTideMonth = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/tide/searchRasgridByNowOfMonth",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
      time: new Date().getTime(),
    },
  });
};

// 根据类型查询24小时以内的灾害数据/disaster/searchDisasterWithTwentyForHoursByType
export const getDisaster = (token, type, department) => {
  return axios({
    method: "get",
    url: urlTrue + "/disaster/searchDisasterWithTwentyForHoursByType",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      type: type,
      departmentName: department,
      time: new Date().getTime(),
    },
  });
};

// 根据类型和年份查询对应记录/disaster/searchDisasterByYearAndType
export const getDisasterByYear = (token, type, year, department) => {
  return axios({
    method: "get",
    url: urlTrue + "/disaster/searchDisasterByYearAndTypeAndDepartment",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      type: type,
      year: year,
      departId: department,
      time: new Date().getTime(),
    },
  });
};

const token = sessionStorage.getItem("token");
// GetTyphoonRouteByID
export const getTyphoonRouteByID = (id) => {
  return axios({
    method: "get",
    // url: 'http://xxs.dhybzx.org:8008/typhoonHandler',
    // url: "https://xxs.dhybzx.org:3000/qstyphoon/typhoonHandler",
    url: urlTrue + "/typhoon/typhoonHandler",
    params: {
      tyID: id,
      m: "getTyphoonPathListByID",
      year: '',
    },
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// 时序查询
// http://10.0.14.172:8081/seriesQueries?featureType=wave&startDateTime=2024-06-15 01:00&endDateTime=2024-06-21 23:00&latitude=30.5&longitude=121.8
export const seriesQueries = (
  token,
  featureType,
  startDateTime,
  endDateTime,
  latitude,
  longitude,
  department
) => {
  return axios({
    method: "post",
    url: urlTrue + "/seriesQueries",
    params: {
      featureType: featureType,
      startDateTime: startDateTime,
      endDateTime: endDateTime,
      latitude: latitude,
      longitude: longitude,
      departmentName: department,
    },
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

export const seriesQueriesNew = (
  token, params
) => {
  return axios({
    method: "post",
    url: urlTrue + "/seriesNewQueries",
    params: {
      ...params,
    },
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// http://10.0.14.172:8081/numberForecast/searchNumberForecastByType?type=wave
export const searchNumberForecastByType = (token, type) => {
  return axios({
    method: "get",
    url: urlTrue + "/numberForecast/searchNumberForecastByType",
    params: {
      type: type,
    },
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// 判断path是否存在
// numberForecast/determinePngExist
export const determinePngExist = (token, path) => {
  return axios({
    method: "get",
    url: urlTrue + "/numberForecast/determinePngExist",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      path,
    },
  });
};

// 获取警戒值
export const getWarning = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/warning/getWarning",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

export const lookAlarm = (data) => {
  return axios({
    method: "get",
    // url: 'http://59.110.0.27:1102/public/'+data,
    url: `${urlTom}${data}`,
    responseType: "blob",
  });
};

export const lookAlarmDocUrl = (data) => {
  return axios({
    method: "get",
    // url: 'http://59.110.0.27:1102/public/'+data,
    url: `${data}`,
    responseType: "blob",
    // 设置请求时长
    // timeout: 60000,
    timeout: 10000 // 设置超时时间为 10 秒
  });
};

export const lookAlarmDocUrl2 = (data) => {
  return axios({
    method: "get",
    // url: 'http://59.110.0.27:1102/public/'+data,
    url: `${data}`,
    responseType: "blob",
    // 设置请求时长
    // timeout: 60000,
    timeout: 10000,// 设置超时时间为 10 秒
    maxBodyLength: Infinity,
    headers: {}
  });

  // return fetch(`${data}`, {
  //   method: "get",
  //   responseType: "blob",
  // })
};

// 获取部门数据
export const getAllDepartment = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/department/searchAllDepartments",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: { pageNum: 0, pageSize: 0 },
  });
};

// 获取角色信息
export const getAllRole = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/role/searchAllRolesAndPermission",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: { pageNum: 1, pageSize: 100 },
  });
};
// 获取全部用户信息
export const getAllUser = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/user/searchUsersByCondition",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
    // params: { pageNum: 1, pageSize: 100 },
  });
};

// 添加用户 addUser
export const addUser = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/user/addUser",
    headers: {
      satoken: token,
      // json
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// editUser
export const editUser = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/user/editUser",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// 获取全部角色 searchAllRoles
export const searchAllRoles = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/role/searchAllRoles",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: { pageNum: 0, pageSize: 0 },
  });
};

// 获取权限
export const getUserPermission = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/user/searchPermissionListByLogin",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// 获取用户部门信息
export const getUserDepartment = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/user/getById",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: params,
  });
};

// /department/searchDepartmentName
export const searchDepartmentName = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/department/searchDepartmentName",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// /department/addDepartment
export const addDepartment = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/department/addDepartment",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// editDepartment
export const editDepartment = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/department/editDepartment",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// /warning/getAllWarning
export const getAllWarning = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/warning/getAllWarning",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// /warning/editWarning
export const editWarning = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/warning/editWarning",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// /disaster/updateStateById

export const updateStateById = (token, params) => {
  return axios({
    method: "post",
    url: urlTrue + "/disaster/updateStateById",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
      // "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
};

// searchDisasterByTypeAndYearAndDepartment
export const searchDisasterByTypeAndYearAndDepartment = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/disaster/searchDisasterByTypeAndYearAndDepartment",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
};

// /uploadFile/searchAll
export const searchAllFile = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/uploadFile/searchAll",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: { pageNum: 0, pageSize: 0 },
  });
};

// uploadFile
export const uploadFile = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/uploadFile/uploadFile",
    headers: {
      satoken: token,
      // "Content-Type": "application/json;charset=UTF-8",
    },
    data: data.file,
  });
};

// /tide/inboundCSVFile

export const inboundCSVFile = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/tide/inboundCSVFile",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    params: {
      ...data,
    },
  });
};

// /view/getViewByTypeAndDepartId
export const getViewByTypeAndDepartId = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/view/getViewByTypeAndDepartId",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
};

// /view/addOrEditView
export const addOrEditView = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/view/addOrEditView",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// /uploadFile/removeUploadFile
export const removeUploadFile = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/uploadFile/removeUploadFile",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    params: {
      ...data,
    },
  });
};

// /department/getWarningDirectorName
export const getWarningDirectorName = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/department/getWarningDirectorName",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// /department/getNCDirectorName 
export const getNCDirectorName = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/department/getNCDirectorName",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// /pnt/searchAllPnt
export const searchAllPnt = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/pnt/searchAllPnt",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// removeDepartment
export const removeDepartment = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/department/removeDepartment",
    headers: {
      satoken: token,
      // "Content-Type": "application/json;charset=UTF-8",
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data: data,
  });
};

// area/selectPubArea
export const selectPubArea = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/area/selectPubArea",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// area/selectSubArea
export const selectSubArea = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/area/selectSubArea",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
};

// removeUser
export const removeUser = (token, data) => {
  return axios({
    method: "delete",
    url: urlTrue + "/user/removeUser",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...data,
    },
  });
};

// /role/addRoleAndPermission
export const addRoleAndPermission = (token, data) => {
  return axios({
    method: "post",
    url: urlTrue + "/role/addRoleAndPermission",
    headers: {
      satoken: token,
      "Content-Type": "application/json;charset=UTF-8",
    },
    data: data,
  });
};

// removeRole
export const removeRole = (token, data) => {
  return axios({
    method: "delete",
    url: urlTrue + "/role/removeRole",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...data,
    },
  });
};

// /permission/searchAllPermissions

export const searchAllPermissions = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/permission/searchAllPermissions",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: { pageNum: 0, pageSize: 0 },
  });
};

// searchRoleListByLogin
export const searchRoleListByLogin = (token) => {
  return axios({
    method: "get",
    url: urlTrue + "/user/searchRoleListByLogin",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
  });
};

// getNewNumberForecastByTypeAndDepart
export const getNewNumberForecastByTypeAndDepart = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/numberForecast/getNewNumberForecastByTypeAndDepart",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
};

// ---------------------------------- 漂浮物相关接口 ----------------------------------------
// 修改文件状态
export const updateStateByIdInPfw = (token, params) => {
  return axios({
    method: "post",
    url: urlTrue + "/floatage/updateStateById",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
}
// 根据部门获取年份数据
export const getYearsByDepartInPfw = (token, params) => {
  return axios({
    method: "get",
    url: urlTrue + "/floatage/getYearsByDepart",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
}
// 获取漂浮物数据信息
export const selectFloatageForecastingInPfw = (token, departmentId, year, state) => {
  return axios({
    method: "get",
    url: urlTrue + "/floatage/selectFloatageForecasting",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      state: state,
      year: year,
      departId: departmentId,
    },
  });
}

// 获取最新漂浮物数据信息
export const getFloatageAlarmInPfw = (token, departmentId, level, state) => {
  return axios({
    method: "get",
    url: urlTrue + "/floatage/searchWithTwentyForHours",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      state: state,
      level: level,
      departId: departmentId,
    },
  });
}

// 时序查询
export const getSequence = (params) => {
  return axios({
    method: "get",
    url: urlDl + "/v1/sequence",
    headers: {
      satoken: token,
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    params: {
      ...params,
    },
  });
}

// 查看文件
export const lookPdf = (data) => {
  return axios({
    method: "get",
    // url: 'http://59.110.0.27:1102/public/'+data,
    url: `${urlDl}/dingTalk/preview`,
    params: {
      id: data,
    },
    responseType: "blob",
  });
};